/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import controller.util.PagingInfo;
import dao.DiplomaJpaController;
import dao.CursoJpaController;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import pagecontroller.JsfUtil;
import dao.exceptions.NonexistentEntityException;
import java.util.ArrayList;
import java.util.Date;
import modelo.Diploma;
import modelo.Curso;
import modelo.SituacaoAluno;
import modelo.TipoCurso;
import pagecontroller.PageManager;

/**
 *
 * @author Dirac
 */
public class DiplomaControllerSearch {

    public DiplomaControllerSearch() {
        //FacesContext facesContext = FacesContext.getCurrentInstance();
        if (JsfUtil.getObjectFromSession("DiplomaJpaController") == null) {
            jpaController = new DiplomaJpaController();
        } else {
            jpaController = (DiplomaJpaController) JsfUtil.getObjectFromSession("DiplomaJpaController");
        }
    }
    private Diploma diploma = null;
    private List<Diploma> diplomas = null;
    private DiplomaJpaController jpaController = null;
    private List<Curso> cursos = null;

    public Diploma getDiploma() {
        if (diploma == null) {
            diploma = new Diploma();
        }
        return diploma;
    }

    public String search() {
        diplomas = jpaController.search(diploma);
        PageManager pm = (PageManager) JsfUtil.getObjectFromSession("PageManager");
        pm.setPageResultSearchDiploma();
        diploma = null;
        return "refreshPage";
    }

    public String searchSituacao() {
        diplomas = jpaController.searchSituacao(diploma.getSituacaoDiploma());
        PageManager pm = (PageManager) JsfUtil.getObjectFromSession("PageManager");
        pm.setPageResultSearchDiploma();
        diploma = null;
        return "refreshPage";
    }

    public List<Diploma> getDiplomas() {
//        this.diplomas = jpaController.findDiplomaEntities();
        return this.diplomas;
    }

    public DiplomaJpaController getJpaController() {
        return jpaController;
    }

    public String load() {


        PageManager pm = (PageManager) JsfUtil.getObjectFromSession("PageManager");
        pm.setPageInserirDiploma();
        return "refreshPage";
    }

    public boolean removeDiplomaList(Diploma diploma) {
        int id=0;

        for(int i = 0; i<=diplomas.size();i++){
            if(diploma.getId()==diplomas.get(i).getId()){
                diplomas.remove(i);
                return true;
            }
        }
        return false;
//
//        for (Diploma ar : diplomas) {
//            if (ar.getId() == diploma.getId()) {
//
//                //diplomas.remove(ar);
//                return true;
//
//            }
//        }
//        return false;
//
//        if (diplomas.contains(diploma)) {
//            diplomas.remove(diploma);
//            return true;
//        }
//        return false;
    }
}
